import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../qianduan/Login.vue'
import Index from '../qianduan/Index.vue'
import zhuce from '../qianduan/reg.vue'
import project from '../qianduan/project.vue'
import agree from '../qianduan/agreement.vue'
import xmfq from '../qianduan/xmfq.vue'
import xmfq1 from '../qianduan/xmfq1.vue'
import huibao from '../qianduan/huibao.vue'

import LoginH from '../houduan/LoginH.vue'
import HomeH from '../houduan/HomeH.vue'

import queren from '../qianduan/queren.vue'
import wancheng from '../qianduan/wancheng.vue'
import xmzl from '../qianduan/xmzl.vue'
import user from '../qianduan/user.vue'
import user_main from '../qianduan/user_main.vue'

import Caidan from '../houduan/caidan.vue'
import Jiaose from '../houduan/jiaose.vue'
import Usermain from '../houduan/Usermaintenance.vue'
import Usermainadd from '../houduan/Usermainadd.vue'
import Shim from '../houduan/shim.vue'
import Guang from '../houduan/guang.vue'
import Xiangm from '../houduan/xangm.vue'
import DingD from '../houduan/dingD.vue'
import YouL from '../houduan/youl.vue'

import smrz from '../qianduan/smrz.vue'
import zhichi from "../qianduan/zhichi.vue"
import zhichi1 from '../qianduan/zhichi1.vue'
import welcome from "../qianduan/welcome.vue"
import FenL from '../houduan/fenl.vue'
import XFenL from '../houduan/xfenl.vue'
import KongZhi from '../houduan/kongzhi.vue'

import dingdan1 from '../qianduan/dingdan1.vue'
import dingdan2 from '../qianduan/dingdan2.vue'





Vue.use(VueRouter)

const routes = [
	{
	    path: '/',
	    redirect:'/welcome'
	},	
	
	
	{
		path:'/project',
		component:project,
		children:[{
			path:'/agree',
			component:agree
		},
		{
			path:'/dingdan1',
			component:dingdan1
		},
		{
			path:'/dingdan2',
			component:dingdan2
		},
		{
			path: '/login',
			component:Login
		},
		{
			path: '/zhuce',
			component:zhuce
		},
		{
			path: '/welcome',
			component:welcome
		},
		{
			path:'/zhichi',
			component:zhichi
		},
		{
			path:'/zhichi1',
			component:zhichi1
		},
		{
		path:'/smrz',
		component:smrz
		},
		{
			path:'/user',
			component:user	,
			children:[{
				path:'/user_main',
				component:user_main
			}]
		},
		{
			path:'/xmzl',
			component:xmzl
		},
		{
			path:'/xmfq',
			component:xmfq,
			children:[{
				path:'/xmfq1',
				component:xmfq1
			},
			{
				path:'/huibao',
				component:huibao
			},			
			{ path:'/queren', component:queren },
			{ path:'/wancheng', component:wancheng }
				]
			}
		]
	},
	// 后端登录路由
	{
		path:'/loginH',
		component:LoginH,
		
	},
	//邮箱登录
	{
		path:'/youx',
		component:YouL,
	},
	//后端登录
	{
		path:'/adminHome',
		component:HomeH,
		children:[
			{
				path:'/caidan',
				component:Caidan
			},
			{
				path:'/jiaose',
				component:Jiaose
			},
			{
				path:'/userH',
				component:Usermain
			},
			{
				path:'/userHadd',
				component:Usermainadd
			},
			{
				path:'/shim',
				component:Shim
			},
			{
				path:'/guang',
				component:Guang
			},
			{
				path:'/xiangm',
				component:Xiangm
			},
			{
				path:'/fenl',
				component:FenL
			},
			{
				path:'/xfenl',
				component:XFenL
			},
			{
				path:'/dingD',
				component:DingD
			},
			{
				path:'/kong',
				component:KongZhi
			}
			
			
		]
	}
]

const router = new VueRouter({
  routes
})

// 挂载路由导航守卫,to表示将要访问的路径，from表示从哪里来，next是下一个要做的操作
router.beforeEach((to, from, next) => {
  if (to.path === '/loginH'||to.path=='/welcome'||to.path=='/login'||to.path=='/zhuce'||to.path=='/youx') {
    return next()
  }

  // 获取token
  const tokenStr = window.sessionStorage.getItem('token')

  if (!tokenStr) {
    return next('/welcome')
  }
  next()
})


export default router
